package com.atguigu.springcloud.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * MybatisPlus配置文件
 */
@Component
public class MybatisPlusHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        // 在createTime字段上加注解@TableField(fill = FieldFill.INSERT)
        this.setFieldValByName("createTime", new Date(), metaObject);
        // 在updateTime字段上加注解@TableField(fill = FieldFill.INSERT_UPDATE)
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 在updateTime字段上加注解@TableField(fill = FieldFill.INSERT_UPDATE)
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
